package com.kaikeba.estack.web.constant;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * web相关的常量类
 *
 * @Auth xingwan
 * @Date 2020/9/26 22:24
 **/
public class WebConstant {


    /**
     * 当前登录用户的key
     */
    public static final String LOGIN_USER_KEY = "web.login.user.key";

    /**
     * web管理页面登录页地址配置key
     */
    public static final String ADMIN_LOGIN_PAGE_URL_KEY = "admin.login.url";


    /**
     * 手端登录登录页地址配置key
     */
    public static final String PHONE_LOGIN_PAGE_URL_KEY = "phone.login.url";

    /**
     * 不需要登录就可以访问url配置的key
     */
    public static final String LOGIN_IGNORE_PAGE_URL_KEY = "login.ignore.urls";

    /**
     * 登录rsa的私钥key
     */
    public static final String LOGIN_RSA_PRIVATE_KEY = "login.rsa.private.key";

    public enum Platform {
        WEB("web"), ANDROID("android"), IOS("ios"), WP("windows phone");

        private String name;

        Platform(String name) {
            this.name = name;
        }

        public static Platform getPlatform(String userAgent) {
            if (StringUtils.isBlank(userAgent)) {
                return WEB;
            }
            return Arrays.stream(values())
                    .filter(platformName -> StringUtils.contains(userAgent, platformName.name))
                    .findFirst()
                    .orElse(WEB);
        }

    }
}
